import * as vscode from 'vscode';
import { translates } from './utils/translateHandler'
import { VueI18nHandler } from './modules/vue-i18n-handler'
export function activate(context: vscode.ExtensionContext) {
    let vueI18nHandler: VueI18nHandler;
    // 整个文件翻译
    let disposable = vscode.commands.registerCommand('easy-vuei18n.translate', () => {

        if (vueI18nHandler?.webviewPanel) {
            vueI18nHandler.webviewPanel.dispose();
        }
        vueI18nHandler = new VueI18nHandler(context);


    });
    context.subscriptions.push(disposable);

    // 按照段落翻译
    let disposable1 = vscode.commands.registerCommand('easy-vuei18n.translateParagraph',
        () => {
            vscode.window.showInformationMessage(`插件!`);
            let editor = vscode.window.activeTextEditor;
            if (!editor) {
                vscode.window.showInformationMessage(`方法已经失效了`);
                return;
            }
            let text = editor.document.getText(); // 使用 getText() 获取整个文档的文本  

            let position = editor.selection.active;
            // vscode.window.showInformationMessage(`Selected text position: ${position.line}, ${position.character}`);



            let selectText = editor.document.getText(editor.selection)

            translates([selectText]).then(res => {
                vscode.window.showInformationMessage(`成功了！`, res);
                vscode.window.activeTextEditor.edit(editBuilder => {
                    // editBuilder.insert(new vscode.Position(0, 0), '插入的文本');
                    editBuilder.replace(editor.selection, res);
                });
            })


            // 使用全局正则表达式替换文本  





            vscode.window.showInformationMessage(`替换成功`);

        }
    );
    context.subscriptions.push(disposable1);
}


export function deactivate() { }
